<?php
include("general_include.php");
if($_SESSION['user_id']!='')
 header("location:dashboard.php");
include "top.php";
include "left.php";
//if(isset($_GET['error'])) $_SESSION['error_forum'] = $_GET['error'];
//if(isset($_GET['username'])) $_SESSION['forum_username'] = $_GET['username'];
//echo $_SESSION['new_reg_id'];
if(isset($_POST['submit']))
{
    $user_type = $_POST['user_type'];
	$userSql="SELECT * FROM ".TABLEPREFIX."_user where user_id='".$_SESSION['new_reg_id']."'";
    $record = $UserManagerObjAjax->GetRecords("Row",$userSql);
	
    if($user_type == 1 || $user_type == 3)
	{
	               $Sql = "INSERT INTO " . TABLEPREFIX."_user_type_user_relation set user_id='".$_SESSION['new_reg_id']."',user_type_id='$user_type',
					date_added='".date('Y-m-d')."'";
					
					$UserManagerObjAjax->Execute($Sql);
					echo "<script>window.location.href='registration_game.php'</script>";
	}
	else
	{
	                
					$tpl_file="email_templates/register_mail.html";
				    $tpl_handler=fopen($tpl_file,"r");
				    $tpl_message=fread($tpl_handler,filesize($tpl_file));
				    fclose($tpl_handler);
			
				    $fromEmail	= "NOOBSKOOL Admin";
					$to	= $record['email'];
			
			        $message = "Welcome to our site. You can access your account by using your email id and given password. <br /> Your login information is given bellow<br />
				    Email : ".$record['email']." and Password : ".$record['password']; 
					$url=$site_url;
					$tpl_message=str_replace("[SITEURL]",$url,$tpl_message);
					$tpl_message=str_replace("[HEADING]",$record['name'],$tpl_message);
					$tpl_message=str_replace("[MESSAGE]",$message,$tpl_message);
					
					$headers  = 'MIME-Version: 1.0' . "\r\n";
					$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
					$headers .= 'From:'.$admin_email . "\r\n" .
									'X-Mailer: PHP/' . phpversion();
					
					mail($to, 'Sucessfull Registration', $tpl_message, $headers);
					//unset($_SESSION['new_reg_id']);
	  
	                echo "<script>window.location.href='registration_success.php'</script>";
	}  
	
	  
	   
  
}  

$smarty->display("registration_type.tpl");
include("footer.php");
?>